//
//  ApplyAuthIDTableViewCell.swift
//  Venus
//
//  Created by qurongxiang on 2018/8/4.
//  Copyright © 2018年 zhaowang. All rights reserved.
//

import UIKit

protocol  ApplyAuthIDTableViewCellDelegate : class {
    func clickApplyAuthID(index:Int)
}

class ApplyAuthIDTableViewCell: UITableViewCell {
    
    fileprivate lazy var justView = ApplyAuthIDImageView(frame: CGRect.zero)
    fileprivate lazy var backView = ApplyAuthIDImageView(frame: CGRect.zero)
    
    weak var delegate: ApplyAuthIDTableViewCellDelegate?
    

    
    override init(style: UITableViewCell.CellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        self.selectionStyle = .none
        setupUI()
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
}
extension ApplyAuthIDTableViewCell {
    @objc func clickJust(imgView:UIImageView) {
        delegate?.clickApplyAuthID(index: 0)
    }
    
    @objc func clickBack(imgView:UIImageView) {
        delegate?.clickApplyAuthID(index: 1)
    }
    
    
    func config(model:ApplyModel , index:IndexPath) {
        justView.imgView.showImageS(model.justUrl)
        backView.imgView.showImageS(model.backUrl)
        justView.imgView.isHidden = model.justUrl.count == 0
        backView.imgView.isHidden = model.backUrl.count == 0
    }
}

extension ApplyAuthIDTableViewCell {
    
    func setupUI() {
        let width = (LayoutCommon.width - 30) / 2
        contentView.addSubview(justView)
        contentView.addSubview(backView)
        let justTapGes = UITapGestureRecognizer(target: self, action: #selector(clickJust(imgView:)))
        justView.addGestureRecognizer(justTapGes)
        
        let backTapGes = UITapGestureRecognizer(target: self, action: #selector(clickBack(imgView:)))
        backView.addGestureRecognizer(backTapGes)
        
        justView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: width, height: width))
            make.left.equalTo(contentView).offset(10)
            make.top.equalToSuperview()
        }
        justView.titleLabel.text = "手持身份证照片"
        
        backView.titleLabel.text = "身份证正面照片"
        
        backView.snp.makeConstraints { (make) in
            make.size.equalTo(CGSize(width: width, height: width))
            make.right.equalTo(contentView).inset(10)
            make.top.equalToSuperview()
        }
    }
}
